char* extra = (char*) xmalloc(25 + strlen(wpt->gc_data->placer.toUtf8().data()) + strlen(wpt->shortname));
sprintf(extra, "\r\nBy %s\r\n%s (%1.1f/%1.1f)",
wpt->gc_data->placer.toUtf8().data(),
- wpt->shortname, wpt->gc_data->diff/10.0,
+ CSTRc(wpt->shortname), wpt->gc_data->diff/10.0,
wpt->gc_data->terr/10.0);
rec->name = xstrappend(rec->name, extra);
xfree(extra);
}
if (global_opts.debug_level >= 1) {
warning("Including waypoint %s at dist:%f lat:%f lon:%f\n",
- wp->shortname, ed->distance, wp->latitude, wp->longitude);
+ CSTRc(wp->shortname), ed->distance, wp->latitude, wp->longitude);
}
}
xfree(ed);
#define R_EARTH 6371000 /* radius of our big blue ball */
#define BCR_DEF_ICON "Standort"
#define BCR_DEF_MPS_ICON "Waypoint"
-#define BCR_UNKNOWN (double) 999999999
+#define BCR_UNKNOWN /*(double) */ 999999999
/*
6371014 would be a better value when converting to f.e. to mapsoure,
{
}
-void bcr_write_line(gbfile* fout, const char* key, int* index, const char* value)
+void bcr_write_line(gbfile* fout, const QString& key, int* index, const QString& value)
{
- if (value == NULL) { /* this is mostly used in the world of windows */
+ if (value.isEmpty()) { /* this is mostly used in the world of windows */
/* so we respectfully add a CR/LF on each line */
- gbfprintf(fout, "%s\r\n", key);
+ gbfprintf(fout, "%s\r\n", CSTR(key));
} else {
char* tmp;
tmp = (value != NULL) ? xstrdup(value) : xstrdup("");
if (index != NULL) {
- gbfprintf(fout, "%s%d=%s\r\n", key, *index, tmp);
+ gbfprintf(fout, "%s%d=%s\r\n", CSTR(key), *index, tmp);
} else {
- gbfprintf(fout, "%s=%s\r\n", key, tmp);
+ gbfprintf(fout, "%s=%s\r\n", CSTR(key), tmp);
}
xfree(tmp);
}
{
queue* elem, *tmp;
waypoint* wpt;
- char* sout;
+ QString sout;
int i, north, east, nmin, nmax, emin, emax;
curr_rte_num++;
bcr_write_line(fout, "[CLIENT]", NULL, NULL); /* client section */
bcr_write_line(fout, "REQUEST", NULL, "TRUE");
- sout = route->rte_name;
+ sout = CSTRc(route->rte_name);
if (rtename_opt != 0) {
sout = rtename_opt;
}
icon = get_bcr_icon_from_icon_descr(wpt->icon_descr);
- xasprintf(&sout, "%s,%.f", icon, BCR_UNKNOWN);
+ sout = QString("%1,%2").arg(icon).arg(BCR_UNKNOWN,10);
bcr_write_line(fout, "STATION", &i, sout);
- xfree(sout);
}
bcr_write_line(fout, "[COORDINATES]", NULL, NULL); /* coords section */
emin = east;
}
- xasprintf(&sout, "%d,%d", east, north);
+ sout = QString::number(east) + "," + QString::number(north);
bcr_write_line(fout, "STATION", &i, sout);
- xfree(sout);
}
bcr_write_line(fout, "[DESCRIPTION]", NULL, NULL); /* descr. section */
i = 0;
QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
- char* s1, *s2, *sout;
+ char* s1, *s2;
i++;
wpt = (waypoint*) elem;
- s1 = wpt->notes;
+ s1 = CSTRc(wpt->notes);
if (s1 == NULL) {
- s1 = wpt->description;
+ s1 = CSTRc(wpt->description);
}
if (prefer_shortnames_opt || (s1 == NULL) || (*s1 == '\0')) {
s2 = s1;
- s1 = wpt->shortname;
+ s1 = CSTRc(wpt->shortname);
} else {
- s2 = wpt->shortname;
+ s2 = CSTRc(wpt->shortname);
}
if (s1 == NULL) {
}
if (*s2) {
- xasprintf(&sout, "%s,%s,@,0", s1, s2);
+ sout = QString("%1,%2,@,0").arg(s1).arg(s2);
} else {
- xasprintf(&sout, "%s,%s,@,0", s1, s1);
+ sout = QString("%1,%2,@,0").arg(s1).arg(s1);
}
bcr_write_line(fout, "STATION", &i, sout);
-
- xfree(s1);
- xfree(s2);
- xfree(sout);
}
- bcr_write_line(fout, "[ROUTE]", NULL, NULL); /* route section */
+ bcr_write_line(fout, "[ROUTE]", NULL, NULL); /* route section */
- xasprintf(&sout, "%d,%d,%d,%d", emin, nmax, emax, nmin);
+// xasprintf(&sout, "%d,%d,%d,%d", emin, nmax, emax, nmin);
+ sout = QString::number(emin) + "," +
+ QString::number(nmax) + "," +
+ QString::number(emax) + "," +
+ QString::number(nmin);
bcr_write_line(fout, "ROUTERECT", NULL, sout);
- xfree(sout);
-
}
static void
#include "cet.h"
#include "cet_util.h"
+#include <QtCore/QDebug>
+
#define MYNAME "cet_util"
static cet_cs_vec_t* cet_cs_vec_root = NULL;
}
w->wpt_flags.cet_converted = 1;
-
- w->shortname = cet_convert_string(wpt->shortname);
- w->description = cet_convert_string(wpt->description);
- w->notes = cet_convert_string(wpt->notes);
-
+#if NEW_STRINGS
+ w->shortname = cet_convert_string(CSTRc(wpt->shortname));
+ w->description = cet_convert_string(CSTRc(wpt->description));
+ w->notes = cet_convert_string(CSTRc(wpt->notes));
+#else
+ w->shortname = cet_convert_string(CSTRc(wpt->shortname));
+ w->description = cet_convert_string(CSTRc(wpt->description));
+ w->notes = cet_convert_string(CSTRc(wpt->notes));
+#endif
if (gc_data) {
const char* placer = cet_convert_string(gc_data->placer);
const char* hint = cet_convert_string(gc_data->hint);
rte->cet_converted = 1;
- rte->rte_name = cet_convert_string(route->rte_name);
- rte->rte_desc = cet_convert_string(route->rte_desc);
+ rte->rte_name = cet_convert_string(CSTRc(route->rte_name));
+ rte->rte_desc = cet_convert_string(CSTRc(route->rte_desc));
const char* rte_url = cet_convert_string(route->rte_url);
rte->rte_url = rte_url;
xfree(rte_url);
gbfprintf(fout, "27-MAR-62 00:00:00 %.6f",
(wpt->altitude != unknown_alt) ? wpt->altitude : 0.0);
if (wpt->description != NULL) {
- gbfprintf(fout, " %s", wpt->description);
+ gbfprintf(fout, " %s", CSTRc(wpt->description));
}
gbfprintf(fout, "\n");
return (tmp);
}
+char*
+csv_stringclean(const QString& string_in, const QString& chararray_in)
+{
+ // TODO(robertl): replace this with a much more Qt-ish implementation.
+ //
+ const char* string = xstrdup(CSTR(string_in));
+ const char* chararray = xstrdup(CSTR(chararray_in));
+
+ char* r = csv_stringclean(string, chararray);
+
+// xfree(string);
+// xfree(chararray);
+ return r;
+}
+
/***********************************************************************************/
/* csv_stringtrim() - trim whitespace and leading and trailing enclosures (quotes) */
/* returns a copy of the modified string */
* way to the target.
*/
#if NEW_STRINGS
+// Pretty much every occurrence of CSTRc() in the code should be treated
+// as a TODO. 90% of them are variadic functions (warning, gbfprint, fatal)
+// that should really support stream operators.
+
+#undef CSTRc
+#define CSTRc(s) s.s_
+
class String {
public:
String() :
s_(NULL) {}
- bool isEmpty() {
- return s_ && *s_;
+
+ bool isEmpty() const {
+ return !(s_ && *s_);
}
+
+ // Support things that expect a pointer. Almost all of these will
+ // ultimately go away, e.g. xfree(shortname);
+#if 1
operator char*() const {
return s_;
}
+#endif
+ // Support shortname = foo;
+#if 1
char* operator=(char* s) {
s_ = s;
return s_;
}
+#endif
+
+ // If something is expecting a QString already, just let them have one.
+ operator QString() const {
+ return s_;
+ }
+
char* s_;
};
+
#else
-typedef char* String;
+#define CSTRc(qstr) (qstr)
+ typedef char* String;
#endif
class waypoint
{
public:
route_head() :
+#if NEW_STRINGS
+#else
rte_name(NULL),
rte_desc(NULL),
+#endif
rte_num(0),
rte_waypt_ct(0),
fs(NULL),
session(NULL) {}
queue Q; /* Link onto parent list. */
queue waypoint_list; /* List of child waypoints */
- char* rte_name;
- char* rte_desc;
+ String rte_name;
+ String rte_desc;
QString rte_url;
int rte_num;
int rte_waypt_ct; /* # waypoints in waypoint list */
void* xmalloc(size_t size);
void* xrealloc(void* p, size_t s);
void xfree(const void* mem);
+#ifndef NEW_STRINGS
char* xstrdup(const char* s);
+#endif
char* xstrdup(const QString& s);
char* xstrndup(const char* s, size_t n);
char* xstrndupt(const char* s, size_t n);
void rtrim(char* s);
char* lrtrim(char* s);
int xasprintf(char** strp, const char* fmt, ...) PRINTFLIKE(2, 3);
+int xasprintf(String* strp, const char* fmt, ...) PRINTFLIKE(2, 3);
int xvasprintf(char** strp, const char* fmt, va_list ap);
char* strupper(char* src);
char* strlower(char* src);
notes_i = 0;
notes_max = 0;
if (global_opts.debug_level >= DBGLVL_L) {
- warning(MYNAME ": read waypoint '%s'\n", wp->description);
+ warning(MYNAME ": read waypoint '%s'\n", CSTRc(wp->description));
}
} else if (wp && id == MSG_WAYPOINT_NOTE_OUT) {
const msg_waypoint_note_t* p = (const msg_waypoint_note_t*) msg_array[i].data;
}
}
if (nn) {
+#if NEW_STRINGS
+#warning gross code avoided.
+abort();
+#else
memcpy(wp->notes + notes_i, s + 2, nn);
+#endif
notes_i += nn;
if (wp->notes[notes_i - 1] == 0) {
notes_i--;
gbfputc('\n', fd);
}
- gbfprintf(fd, "Cache ID: %s\n", wp->shortname);
+ gbfprintf(fd, "Cache ID: %s\n", CSTRc(wp->shortname));
if (gc_sym && opt_gcsym && atoi(opt_gcsym)) {
gbfprintf(fd, "%s\n", waypoint_symbol(gc_sym));
*symbol = gc_sym;
break;
}
if (--attempt == 0) {
- fatal(MYNAME ": reading track '%s' failed\n", track->rte_name);
+ fatal(MYNAME ": reading track '%s' failed\n", CSTRc(track->rte_name));
}
if (global_opts.debug_level >= DBGLVL_M) {
- warning(MYNAME ": timed out reading track '%s', retrying\n", track->rte_name);
+ warning(MYNAME ": timed out reading track '%s', retrying\n", CSTRc(track->rte_name));
}
m.size = MSG_BREAK_SIZE;
memset(m.data, 0, m.size);
}
message_free(&m);
if (msg_array_n == 0 || message_get_id(&msg_array[0]) != MSG_TRACK_HEADER_OUT) {
- fatal(MYNAME ": reading track '%s' failed (missing track header)\n", track->rte_name);
+ fatal(MYNAME ": reading track '%s' failed (missing track header)\n", CSTRc(track->rte_name));
}
// process track messages
p = (const msg_track_header_t*) msg_array[0].data;
if (id == MSG_TRACK_POINT_OUT) {
decode_track_point(msg_array[i].data, &wp_array_i, n_point);
} else {
- fatal(MYNAME ": unexpected message %x while reading track '%s'\n", id, track->rte_name);
+ fatal(MYNAME ": unexpected message %x while reading track '%s'\n", id, CSTRc(track->rte_name));
}
message_free(&msg_array[i]);
}
fatal(MYNAME ": track point count mismatch, expected %u, got %u\n", n_point, wp_array_i);
}
if (global_opts.debug_level >= DBGLVL_L) {
- warning(MYNAME ": read track '%s' %u points\n", track->rte_name, n_point);
+ warning(MYNAME ": read track '%s' %u points\n", CSTRc(track->rte_name), n_point);
}
for (i = 0; i < n_point; i++) {
track_add_wpt(track, wp_array[i]);
break;
}
if (--attempt == 0) {
- fatal(MYNAME ": reading route '%s' failed (timed out)\n", route->rte_name);
+ fatal(MYNAME ": reading route '%s' failed (timed out)\n", CSTRc(route->rte_name));
}
if (global_opts.debug_level >= DBGLVL_M) {
- warning(MYNAME ": timed out reading route route '%s', retrying\n", route->rte_name);
+ warning(MYNAME ": timed out reading route route '%s', retrying\n", CSTRc(route->rte_name));
}
m.size = MSG_BREAK_SIZE;
memset(m.data, 0, m.size);
wp_array = (waypoint**) xcalloc(total, sizeof(*wp_array));
if (global_opts.debug_level >= DBGLVL_L) {
warning(MYNAME ": route '%s' %u points, %u shape points\n",
- route->rte_name, route_total, shape_total);
+ CSTRc(route->rte_name), route_total, shape_total);
}
message_free(&msg_array[0]);
for (i = 1; i < msg_array_n; i++) {
if (id == MSG_ROUTE_POINT_OUT) {
wp_array[wp_array_i] = decode_route_point(msg_array[i].data);
if (global_opts.debug_level >= DBGLVL_L) {
- warning(MYNAME ": route point '%s'\n", wp_array[wp_array_i]->shortname);
+ warning(MYNAME ": route point '%s'\n", CSTRc(wp_array[wp_array_i]->shortname));
}
wp_array_i++;
} else if (id == MSG_ROUTE_SHAPE_OUT) {
decode_route_shape(msg_array[i].data, &wp_array_i);
} else {
- fatal(MYNAME ": unexpected message %x while reading route '%s'\n", id, route->rte_name);
+ fatal(MYNAME ": unexpected message %x while reading route '%s'\n", id, CSTRc(route->rte_name));
}
message_free(&msg_array[i]);
}
garmin_fs_t* gmsd = GMSD_FIND(wpt);
write_wcstr(DST_DYN_POI);
- write_wcstr((wpt->shortname) ? wpt->shortname : "WPT");
+ write_wcstr((wpt->shortname) ? CSTRc(wpt->shortname) : "WPT");
write_wcstr((wpt->notes) ? wpt->notes : wpt->description);
write_wcstr(NULL); /* house number */
destinator_rtept_disp(const waypoint* wpt)
{
write_wcstr(DST_ITINERARY);
- write_wcstr((wpt->shortname) ? wpt->shortname : "RTEPT");
+ write_wcstr((wpt->shortname) ? CSTRc(wpt->shortname) : "RTEPT");
write_wcstr((wpt->notes) ? wpt->notes : wpt->description);
gbfputint32(0, fout);
queue* curr, *prev;
QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++;
}
- write_str(trk && trk->rte_name && *trk->rte_name ? trk->rte_name : "Name", fout);
+ write_str(trk && trk->rte_name && *trk->rte_name ? CSTRc(trk->rte_name) : "Name", fout);
xasprintf(&cout, "%d trackpoints and %d waypoints", count, waypt_count());
write_str(cout, fout);
if (names > 1) {
write_str(wpt->description, fout);
}
- write_str(wpt->shortname && *wpt->shortname ? wpt->shortname : "Name", fout);
+ write_str(wpt->shortname && *wpt->shortname ? CSTRc(wpt->shortname) : "Name", fout);
}
static void
} else {
speed = MPS_TO_KPH(speed);
}
- xasprintf(&str, "%s@%.f", wpt->shortname ? wpt->shortname : "WPT", speed);
+ xasprintf(&str, "%s@%.f", wpt->shortname ? CSTRc(wpt->shortname) : "WPT", speed);
if (wpt->shortname) {
xfree(wpt->shortname);
}
if (! valid) {
gbfprintf(fout, "#####\n");
fatal(MYNAME ": %s (%s) is outside of convertable area \"%s\"!\n",
- wpt->shortname ? wpt->shortname : "Waypoint",
+ wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint",
pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0),
gt_get_mps_grid_longname(grid_index, MYNAME));
}
wpt_type = gt_waypt_class_names[0];
}
- gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? wpt->shortname : "");
+ gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? CSTRc(wpt->shortname) : "");
if (wpt_class <= gt_waypt_class_airport_ndb) {
const char* temp = wpt->notes;
if (temp == NULL) {
gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[route_header]);
}
- print_string("\r\nRoute\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
+ print_string("\r\nRoute\t%s\t", current_trk->rte_name ? CSTRc(current_trk->rte_name) : "");
print_distance(cur_info->length, 0, 1, 0);
print_course(cur_info->first_wpt, cur_info->last_wpt);
gbfprintf(fout, "\t%d waypoints\t", cur_info->count);
waypoint* prev = cur_info->prev_wpt;
gbfprintf(fout, "Route Waypoint\t");
- gbfprintf(fout, "%s\t", wpt->shortname);
+ gbfprintf(fout, "%s\t", CSTRc(wpt->shortname));
if (prev != NULL) {
double dist = waypt_distance_ex(prev, wpt);
gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[track_header]);
}
- print_string("\r\nTrack\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
+ print_string("\r\nTrack\t%s\t", current_trk->rte_name ? CSTRc(current_trk->rte_name) : "");
print_date_and_time(cur_info->start, 0);
print_date_and_time(cur_info->time, 1);
print_distance(cur_info->length, 0, 1, 0);
xfree(qs);
return rv;
}
+#if NEW_STRINGS
+int
+gbfputs(const String& s, gbfile* file)
+{
+ return gbfwrite(s.s_, 1, strlen(s.s_), file);
+}
+#endif
/*
* gbfwrite: (as fwrite)
return gbfputcstr(qPrintable(s), file);
}
+#if NEW_STRINGS
+int
+gbfputcstr(const String& s, gbfile* file)
+{
+ return gbfputcstr(s.s_, file);
+}
+#endif
+
/*
* gbfputcstr: write a pascal string into a stream
* return the number of written characters
return r;
}
+#if NEW_STRINGS
+int
+gbfputpstr(const String& s, gbfile* file)
+{
+ return gbfputpstr(s.s_, file);
+}
+#endif
+
/* Much more higher level functions */
gbsize_t
int gbfputc(int c, gbfile* file);
int gbfputs(const char* s, gbfile* file);
int gbfputs(const QString& s, gbfile* file);
+#if NEW_STRINGS
+class String;
+int gbfputs(const String& s, gbfile* file);
+#endif
int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
int gbfflush(gbfile* file);
int gbfputdbl(const double d, gbfile* file); // write a double value
int gbfputflt(const float f, gbfile* file); // write a float value
+
int gbfputcstr(const char* s, gbfile* file); // write string including '\0'
int gbfputcstr(const QString& s, gbfile* file); // write string including '\0'
+#if NEW_STRINGS
+int gbfputcstr(const String& s, gbfile* file); // write string including '\0'
+#endif
+
int gbfputpstr(const char* s, gbfile* file); // write as pascal string
int gbfputpstr(const QString& s, gbfile* file); // write as pascal string
+#if NEW_STRINGS
+int gbfputpstr(const String& s, gbfile* file); // write as pascal string
+#endif
gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count);
if (fabs(dist) > 100) {
warning(MYNAME ": Route point mismatch!\n");
warning(MYNAME ": \"%s\" from waypoints differs to \"%s\"\n",
- tmp->shortname, ref->shortname);
+ CSTRc(tmp->shortname), CSTRc(ref->shortname));
fatal(MYNAME ": from route table by more than %0.1f meters!\n",
dist);
warnings++;
if (warnings > 3) {
- fatal(MYNAME "-rte_pt \"%s\": too many warnings!\n", wpt->shortname);
+ fatal(MYNAME "-rte_pt \"%s\": too many warnings!\n", CSTRc(wpt->shortname));
}
- warning(MYNAME "-rte_pt \"%s\" (class %d): possible error in route.\n", wpt->shortname, wpt_class);
+ warning(MYNAME "-rte_pt \"%s\" (class %d): possible error in route.\n", CSTRc(wpt->shortname), wpt_class);
warning(MYNAME "-rte_pt (dump):");
for (i = 0; i < 18; i++) {
warning(" %02x", (unsigned char)buf[i]);
if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
fatal("Invalid latitude %f in waypoint %s.\n",
- lat_orig, wpt->shortname ? wpt->shortname : "<no name>");
+ lat_orig, wpt->shortname ? CSTRc(wpt->shortname) : "<no name>");
if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
fatal("Invalid longitude %f in waypoint %s.\n",
- lon_orig, wpt->shortname ? wpt->shortname : "<no name>");
+ lon_orig, wpt->shortname ? CSTRc(wpt->shortname) : "<no name>");
}
/*-----------------------------------------------------------------------------*/
descr = (wpt_class < gt_waypt_class_map_point) ?
ld : wpt->description;
if ((descr != NULL) && (wpt_class >= gt_waypt_class_map_point) && \
- descr == wpt->shortname ) {
+ descr == CSTRc(wpt->shortname)) {
descr.clear();
}
FWRITE_CSTR(descr);
we need to keep track of log_wpt counts so we don't collide with
dupe shortnames.
*/
-
if ((wpt_tmp->shortname) && (strlen(wpt_tmp->shortname) > 2)) {
/* copy of the shortname */
lwp_tmp->shortname = (char*) xcalloc(7, 1);
writer->writeOptionalTextElement("name", oname);
writer->writeOptionalTextElement("cmt", waypointp->description);
-
+#if NEW_STRINGS
+ if (!waypointp->notes.isEmpty()) {
+#else
if (waypointp->notes && waypointp->notes[0]) {
+#endif
writer->writeTextElement("desc", waypointp->notes);
} else {
writer->writeOptionalTextElement("desc", waypointp->description);
GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude,
&utme, &utmn, &utmz, &utmzc);
- gbfprintf(file_out, "\n<a name=\"%s\"><hr></a>\n", wpt->shortname);
+ gbfprintf(file_out, "\n<a name=\"%s\"><hr></a>\n", CSTRc(wpt->shortname));
gbfprintf(file_out, "<table width=\"100%%\">\n");
gbfprintf(file_out, "<tr><td><p class=\"gpsbabelwaypoint\">%s - ",(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname);
cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1);
gbfprintf(file_out, "<a href=\"%s\">%s</a>", link.url_.toUtf8().data(), d);
xfree(d);
} else {
- gbfprintf(file_out, "%s", wpt->description);
+ gbfprintf(file_out, "%s", CSTRc(wpt->description));
}
if (!wpt->gc_data->placer.isEmpty()) {
gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data());
gbfprintf(file_out, "<p class=\"gpsbabelhint\"><strong>Hint:</strong> %s</p>\n", hint);
xfree(hint);
} else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
- gbfprintf(file_out, "<p class=\"gpsbabelnotes\">%s</p>\n", wpt->notes);
+ gbfprintf(file_out, "<p class=\"gpsbabelnotes\">%s</p>\n", CSTRc(wpt->notes));
}
fs_gpx = NULL;
char* key;
waypoint* tmpwpt;
- xasprintf(&key, "%s\01%.9f\01%.9f", wpt->shortname, wpt->latitude, wpt->longitude);
+ xasprintf(&key, "%s\01%.9f\01%.9f", CSTRc(wpt->shortname), wpt->latitude, wpt->longitude);
if (!(tmpwpt = map[key])) {
tmpwpt = (waypoint*)wpt;
map[key] = (waypoint*) wpt;
// Other header data may have been stored in track description
if (track && track->rte_desc && strncmp(track->rte_desc, HDRMAGIC, strlen(HDRMAGIC)) == 0) {
- for (str = strtok(track->rte_desc + strlen(HDRMAGIC) + strlen(HDRDELIM), HDRDELIM);
+ for (str = strtok(CSTRc(track->rte_desc) + strlen(HDRMAGIC) + strlen(HDRDELIM), HDRDELIM);
str; str = strtok(NULL, HDRDELIM)) {
gbfprintf(file_out, "%s\r\n", str);
}
gbfprintf(fout, "\t<INFORMATIONS>\n");
gbfprintf(fout, "\t\t<NB_ETAPES>%d</NB_ETAPES>\n", track->rte_waypt_ct);
if (track->rte_desc != NULL) {
- gbfprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", track->rte_desc);
+ gbfprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", CSTRc(track->rte_desc));
}
gbfprintf(fout, "\t</INFORMATIONS>\n");
}
}
if (global_opts.debug_level >= 1)
- printf(MYNAME " parse_waypt: Waypt name = %s Lat = %f Lon = %f alt = %f\n",wpt_tmp->shortname, wpt_tmp->latitude,
+ printf(MYNAME " parse_waypt: Waypt name = %s Lat = %f Lon = %f alt = %f\n",CSTRc(wpt_tmp->shortname), wpt_tmp->latitude,
wpt_tmp->longitude, wpt_tmp->altitude);
text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
}
if (global_opts.debug_level >= 1) {
- printf(MYNAME " parse_trails: trail name = %s\n", trk_head->rte_name);
+ printf(MYNAME " parse_trails: trail name = %s\n", CSTRc(trk_head->rte_name));
}
/* visible */
if (global_opts.debug_level >= 1)
printf(MYNAME " route_hdr: route name \"%s\" num_legs = %d\n",
- rte->rte_name, num_legs);
+ CSTRc(rte->rte_name), num_legs);
}
if (global_opts.debug_level >= 2) {
printf(MYNAME " adding waypt %s (%s) to table at index %d\n",
- wpt->shortname, wpt->description, waypt_table_ct);
+ CSTRc(wpt->shortname), CSTRc(wpt->description), waypt_table_ct);
}
waypt_table[waypt_table_ct] = (waypoint*)wpt;
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_waypoints: name = %s, uid_unit = %u, "
"uid_seq_low = %d, uid_seq_high = %d, lat = %f, lon = %f, depth = %f\n",
- wpt_tmp->shortname, fsdata->uid_unit,
+ CSTRc(wpt_tmp->shortname), fsdata->uid_unit,
fsdata->uid_seq_low, fsdata->uid_seq_high,
wpt_tmp->latitude, wpt_tmp->longitude, wpt_tmp->depth);
}
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_routes: route name=%s has %d waypoints\n",
- rte_head->rte_name, num_legs);
+ CSTRc(rte_head->rte_name), num_legs);
}
for (j = 0; j < num_legs; ++j) {
if (wpt_tmp) {
if (global_opts.debug_level >= 2) {
printf(MYNAME " parse_routes: added wpt %s to route %s\n",
- wpt_tmp->shortname, rte_head->rte_name);
+ CSTRc(wpt_tmp->shortname), CSTRc(rte_head->rte_name));
}
route_add_wpt(rte_head, waypt_dupe(wpt_tmp));
}
if (global_opts.debug_level >= 1) {
printf(MYNAME " parse_trails: trail %d name=%s has %d trackpoints\n",
- trk_num, trk_head->rte_name, num_trail_pts);
+ trk_num, CSTRc(trk_head->rte_name), num_trail_pts);
}
for (j = 0; j < num_trail_pts; ++j) {
if (global_opts.debug_level >= 2) {
printf(MYNAME " parse_routes: added trackpoint %f,%f to route %s\n",
- wpt_tmp->latitude, wpt_tmp->longitude, trk_head->rte_name);
+ wpt_tmp->latitude, wpt_tmp->longitude, CSTRc(trk_head->rte_name));
}
}
}
for (i = 0; i < waypt_table_ct; ++i) {
if (global_opts.debug_level >= 2) {
printf(MYNAME " writing out waypt %d (%s - %s)\n",
- i, waypt_table[i]->shortname, waypt_table[i]->description);
+ i, CSTRc(waypt_table[i]->shortname), CSTRc(waypt_table[i]->description));
}
lowranceusr4_waypt_disp((const waypoint*)waypt_table[i]);
}
{
if (global_opts.debug_level >= 1) {
printf(MYNAME " writing route #%d (%s) with %d waypts\n",
- route_uid, rte->rte_name, rte->rte_waypt_ct);
+ route_uid, CSTRc(rte->rte_name), rte->rte_waypt_ct);
}
/* UID unit number */
if (global_opts.debug_level >= 2) {
if (waypt_idx > waypt_table_ct) {
printf(MYNAME " WARNING: failed finding waypoint %s in waypoint table\n",
- wpt->shortname);
+ CSTRc(wpt->shortname));
} else {
printf(MYNAME " adding waypt %d (%s) to route\n",
- waypt_idx, waypt_table[waypt_idx]->shortname);
+ waypt_idx, CSTRc(waypt_table[waypt_idx]->shortname));
}
}
{
if (global_opts.debug_level >= 1) {
printf(MYNAME " writing track %d (%s) with %d trackpoints\n",
- track_uid, trk->rte_name, trk->rte_waypt_ct);
+ track_uid, CSTRc(trk->rte_name), trk->rte_waypt_ct);
}
/* UID unit number */
QString icon_token;
char* owpt;
char* odesc;
- char* isrc = NULL;
ilat = waypointp->latitude;
ilon = waypointp->longitude;
icon_token = mag_find_token_from_descr(get_cache_icon(waypointp));
}
- isrc = waypointp->notes ? waypointp->notes : waypointp->description;
+ String isrc = waypointp->notes ? waypointp->notes : waypointp->description;
owpt = global_opts.synthesize_shortnames ?
mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname;
odesc = isrc ? isrc : (char*)"";
expbuf[0] = 0;
if (explorist) {
snprintf(expbuf, sizeof(expbuf), "%s,",
- rte->rte_name ? rte->rte_name : "");
+ rte->rte_name ? CSTRc(rte->rte_name) : "");
}
sprintf(obuff, "PMGNRTE,%d,%d,c,%d,%s%s,%s",
numlines, thisline,
if (r.isEmpty()) {
rname = "Route";
} else {
- rname = rte->rte_name;
+ rname = CSTRc(rte->rte_name);
}
gbfputpstr(rname, mapsend_file_out);
if ((wpt->shortname[0] == 1) && (wpt->latitude == 0) && (wpt->longitude == 0)) {
mmo_data_t* data;
waypoint* wpt2;
-
+#if NEW_STRINGS
+#warning this code is on drugs.
+ abort();
+#else
sscanf(wpt->shortname + 1, "%p", &data);
+#endif
wpt2 = (waypoint*)data->data;
wpt->latitude = wpt2->latitude;
DBG(("write", "waypoint \"%s\"\n", wpt->shortname ? wpt->shortname : "Mark"));
objid = mmo_write_obj_head("CObjWaypoint",
- (wpt->shortname && *wpt->shortname) ? wpt->shortname : "Mark", time, obj_type_wpt);
+ (wpt->shortname && *wpt->shortname) ? CSTRc(wpt->shortname) : "Mark", time, obj_type_wpt);
data = mmo_register_object(objid, wpt, wptdata);
data->refct = 1;
mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks");
}
objid = mmo_write_obj_head("CObjRoute",
- (rte->rte_name && *rte->rte_name) ? rte->rte_name : "Route", time, obj_type_rte);
+ (rte->rte_name && *rte->rte_name) ? CSTRc(rte->rte_name) : "Route", time, obj_type_rte);
mmo_register_object(objid, rte, rtedata);
mmo_write_category("CCategory", "Route");
gbfputc(0, fout); /* unknown */
}
objid = mmo_write_obj_head("CObjTrack",
- (trk->rte_name && *trk->rte_name) ? trk->rte_name : "Track", gpsbabel_time, obj_type_trk);
+ (trk->rte_name && *trk->rte_name) ? CSTRc(trk->rte_name) : "Track", gpsbabel_time, obj_type_trk);
mmo_write_category("CCategory", "Track");
gbfputuint16(trk->rte_waypt_ct, fout);
rte_name = "NO NAME";
}
if (route_id_ptr > MAX_ROUTE_LENGTH) {
- fatal(MYNAME ": Route %s too long\n", route->rte_name);
+ fatal(MYNAME ": Route %s too long\n", CSTRc(route->rte_name));
}
src = (route_id_ptr + MAX_SUBROUTE_LENGTH) / MAX_SUBROUTE_LENGTH;
for (i = 0, bh = htable; i < ct; i++, bh++) {
if (last_crc == bh->crc) {
- snprintf(ssid, sizeof ssid, "%s/%d", bh->wpt->shortname, ++serial);
+ snprintf(ssid, sizeof ssid, "%s/%d", CSTRc(bh->wpt->shortname), ++serial);
xfree(bh->wpt->shortname);
bh->wpt->shortname = xstrdup(ssid);
} else {
} else if (strcmp(key, "note") == 0) {
if (wpt->notes) {
char* tmp;
- xasprintf(&tmp, "%s; %s", wpt->notes, str);
+ xasprintf(&tmp, "%s; %s", CSTRc(wpt->notes), str);
xfree(wpt->notes);
wpt->notes = tmp;
} else {
osm_name_from_wpt(const waypoint* wpt)
{
QString name = QString("%1\01%2\01%3")
- .arg((wpt->shortname) ? wpt->shortname : "")
+ .arg((wpt->shortname) ? CSTRc(wpt->shortname) : "")
.arg(wpt->latitude)
.arg(wpt->longitude);
return name;
ozi_openfile(ozi_ofname);
gbfprintf(file_out, ozi_trk_header,
altunit == 'f' ? "Feet" : "Meters",
- rte->rte_name ? rte->rte_name : "ComplimentsOfGPSBabel");
+ rte->rte_name ? CSTRc(rte->rte_name) : "ComplimentsOfGPSBabel");
}
track_out_count++;
gbfprintf(file_out, "R,%d,%s,%s,\r\n",
route_out_count,
- rte->rte_name ? rte->rte_name : "",
- rte->rte_desc ? rte->rte_desc : "");
+ rte->rte_name ? CSTRc(rte->rte_name) : "",
+ rte->rte_desc ? CSTRc(rte->rte_desc) : "");
}
gbfprintf(file_out, "W,%d,,%d,%s,%.6f,%.6f,%s,0,1,3,0,65535,%s,0,0\r\n",
route_out_count,
route_wpt_count,
- waypointp->shortname ? waypointp->shortname : "",
+ waypointp->shortname ? CSTRc(waypointp->shortname) : "",
waypointp->latitude,
waypointp->longitude,
ozi_time,
- waypointp->description ? waypointp->description : "");
+ waypointp->description ? CSTRc(waypointp->description) : "");
}
fabs(lon),
tbuf,
(wpt->altitude == unknown_alt) ? -9999 : wpt->altitude,
- (wpt->description != NULL) ? wpt->description : "",
+ (wpt->description != NULL) ? CSTRc(wpt->description) : "",
0.0,
icon_token);
}
wpt->shortname = xstrdup(s);
s = csv_lineparse(NULL, "\\w", "", linecount);
if (!s) {
- fatal(MYNAME "Invalid latitude %s", wpt->shortname);
+ fatal(MYNAME "Invalid latitude %s", CSTRc(wpt->shortname));
}
wpt->latitude = wppos_to_dec(s);
s = csv_lineparse(NULL, "\\w", "", linecount);
if (!s) {
- fatal(MYNAME "Invalid longitude %s", wpt->shortname);
+ fatal(MYNAME "Invalid longitude %s", CSTRc(wpt->shortname));
}
wpt->longitude = wppos_to_dec(s);
waypt_add(wpt);
wpt = find_waypt_by_name(str);
if (wpt == NULL)
fatal(MYNAME ": No associated waypoint for route point %s (Route %s)!\n",
- str, rte->rte_name);
+ str, CSTRc(rte->rte_name));
route_add_wpt(rte, waypt_dupe(wpt));
}
prev = thisw;
if (!thisw->shortname || !thisw->shortname[0]) {
snprintf(tkptname, sizeof(tkptname), "%s-%d",
- trk->rte_name ? trk->rte_name : "" , tkpt);
+ trk->rte_name ? CSTRc(trk->rte_name) : "" , tkpt);
thisw->shortname = xstrdup(tkptname);
}
tkpt++;
if (strcmp(wpt->description, wpt->shortname)) {
- gbfprintf(file_out, "%s", wpt->description);
+ gbfprintf(file_out, "%s", CSTRc(wpt->description));
if (!wpt->gc_data->placer.isEmpty()) {
gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data());
}
xfree(hint);
}
} else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
- gbfprintf(file_out, "\n%s\n", wpt->notes);
+ gbfprintf(file_out, "\n%s\n", CSTRc(wpt->notes));
}
fs_gpx = NULL;
if (global_opts.smart_names &&
blocks->start[i].wpt->gc_data->diff &&
blocks->start[i].wpt->gc_data->terr) {
- snprintf(desc_field,sizeof(desc_field),"%s(t%ud%u)%s(type%dcont%d)",blocks->start[i].wpt->description,
+ snprintf(desc_field,sizeof(desc_field),"%s(t%ud%u)%s(type%dcont%d)",CSTRc(blocks->start[i].wpt->description),
blocks->start[i].wpt->gc_data->terr/10,
blocks->start[i].wpt->gc_data->diff/10,
- blocks->start[i].wpt->shortname,
+ CSTRc(blocks->start[i].wpt->shortname),
(int) blocks->start[i].wpt->gc_data->type,
(int) blocks->start[i].wpt->gc_data->container);
//Unfortunately enums mean we get numbers for cache type and container.
} else {
snprintf(desc_field, sizeof(desc_field), "%s",
- blocks->start[i].wpt->description);
+ CSTRc(blocks->start[i].wpt->description));
}
write_long(f, strlen(desc_field) + 14);
write_float_as_long(f, blocks->start[i].wpt->longitude*100000);
snprintf(buff, sizeof(buff), "%s-%s", opt_title, tbuff);
}
} else if ((track->rte_name != NULL) && (strlen(track->rte_name) > 0)) {
- snprintf(buff, sizeof(buff), "%s-%s", track->rte_name, tbuff);
+ snprintf(buff, sizeof(buff), "%s-%s", CSTRc(track->rte_name), tbuff);
} else {
strncpy(buff, tbuff, sizeof(buff));
}
dest->rte_num = src->rte_num;
/* name in the form TRACKNAME #n */
if (src->rte_name) {
- xasprintf(&dest->rte_name, "%s #%d", src->rte_name, ++trk_seg_num);
+ xasprintf(&dest->rte_name, "%s #%d", CSTRc(src->rte_name), ++trk_seg_num);
}
/* Insert after original track or after last newly
current_trk = route_head_alloc();
track_add_head(current_trk);
if (rte->rte_name && *rte->rte_name) {
- xasprintf(¤t_trk->rte_desc, "Generated from route %s", rte->rte_name);
+ xasprintf(¤t_trk->rte_desc, "Generated from route %s", CSTRc(rte->rte_name));
current_trk->rte_name = xstrdup(rte->rte_name); /* name the new trk */
}
}
current_rte = route_head_alloc();
route_add_head(current_rte);
if (trk->rte_name && *trk->rte_name) {
- xasprintf(¤t_rte->rte_desc, "Generated from track %s", trk->rte_name);
+ xasprintf(¤t_rte->rte_desc, "Generated from track %s", CSTRc(trk->rte_name));
current_rte->rte_name = xstrdup(trk->rte_name); /* name the new rte */
}
}
{
gbfprintf(fout, "#####\n");
fatal(MYNAME ": %s (%s) is outside of convertable area of grid \"%s\"!\n",
- wpt->shortname ? wpt->shortname : "Waypoint",
+ wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint",
pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0),
gt_get_mps_grid_longname(unicsv_grid_idx, MYNAME));
}
xfree(t);
}
+#if NEW_STRINGS
+static void
+unicsv_print_str(const String& s)
+{
+ unicsv_print_str(s.s_);
+}
+#endif
+
static void
unicsv_print_data_time(const QDateTime& idt)
{
const char* shortname;
garmin_fs_t* gmsd;
- shortname = (wpt->shortname) ? wpt->shortname : "";
+ shortname = (wpt->shortname) ? CSTRc(wpt->shortname) : "";
gmsd = GMSD_FIND(wpt);
if (*shortname) {
const geocache_data* gc_data = NULL;
unicsv_waypt_ct++;
- shortname = (wpt->shortname) ? wpt->shortname : "";
+ shortname = (wpt->shortname) ? CSTRc(wpt->shortname) : "";
gmsd = GMSD_FIND(wpt);
if (unicsv_datum_idx == DATUM_WGS84) {
return res;
}
+#if NEW_STRINGS
+int
+xasprintf(String* strp, const char* fmt, ...)
+{
+ va_list args;
+ int res;
+ va_start(args, fmt);
+ res = xvasprintf(&strp->s_, fmt, args);
+ va_end(args);
+
+ return res;
+}
+#endif
int
xvasprintf(char** strp, const char* fmt, va_list ap)
latint = abs((int) wpt->latitude);
gbfprintf(file_out, "BEGIN:VCARD\nVERSION:3.0\n");
- gbfprintf(file_out, "N:%s;%s;;;\n", wpt->description,wpt->shortname);
+ gbfprintf(file_out, "N:%s;%s;;;\n", CSTRc(wpt->description),CSTRc(wpt->shortname));
gbfprintf(file_out, "ADR:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N', abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint));
if (wpt->HasUrlLink()) {
if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
fatal("%s: Invalid latitude %f in waypoint '%s'.\n",
wpt->session->name,
- lat_orig, wpt->shortname);
+ lat_orig, CSTRc(wpt->shortname));
if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
fatal("Invalid longitude %f in waypoint '%s'.\n",
- lon_orig, wpt->shortname);
+ lon_orig, CSTRc(wpt->shortname));
/*
* Some input may not have one or more of these types so we
{
gbfprintf(fout, "#####\n");
fatal(MYNAME ": %s (%s) is outside of convertable area \"%s\"!\n",
- wpt->shortname ? wpt->shortname : "Waypoint",
+ wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint",
pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0),
gt_get_mps_grid_longname(grid_swiss, MYNAME));
}